package com.ant.storage.controller;
import com.ant.storage.common.PageRequest;
import com.ant.storage.common.ResultPage;
import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.ReimbursementDto;
import com.ant.storage.handler.AntException;
import com.ant.storage.pojo.Reimbursement;
import com.ant.storage.service.IReimbursementService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author melon
 * @since 2022-07-26
 */
@RestController
@RequestMapping("/reimbursement")
@Api(tags = "报销接口")
public class ReimbursementController {

    @Autowired
    private IReimbursementService reimbursementService;

    @ApiOperation(value = "获取报销信息列表接口")
    @GetMapping("/getReimbursementPage")
    public ResultPage getReimbursementPage(ReimbursementDto reimbursementDto)
    {
        return ResultPage.success("获取成功",reimbursementService.getPageList(reimbursementDto));
    }

    @ApiOperation(value = "报销申请通过")
    @GetMapping("/ReimbursementAdopt/{id}")
    private ResultVo ReimbursementAdopt(@PathVariable("id") Integer id) {
        if(id==null) {
            throw  new AntException("id不能为空");
        }else {
            reimbursementService.update(new UpdateWrapper<Reimbursement>()
                    .set("handler_status",1)
                    .set("handler_by","admin")
                    .set("handler_time",new Date())
                    .eq("id",id));
            return ResultVo.success("申请通过");
        }
    }


    @ApiOperation(value = "报销申请填写")
    @PostMapping("/ReimbursemenSave")
    private ResultVo ReimbursemenSave(@RequestBody Reimbursement reimbursement) {
        return  reimbursementService.reimbursemenSave(reimbursement);
    }
}
